package pers.qianyu.module.image.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.module.core.comm.HttpResult;
import pers.qianyu.module.core.comm.Pagination;
import pers.qianyu.module.core.domain.image.dto.NoticeForUpdateStatusDTO;
import pers.qianyu.module.core.domain.image.query.NoticeQuery;
import pers.qianyu.module.core.domain.image.vo.NoticeVO;
import pers.qianyu.module.image.service.NoticeService;
import pers.qianyu.module.logging.annotation.ControllerLog;
import pers.qianyu.module.logging.enums.BusinessType;

/**
 * @author mizzle rain
 * @date 2021-02-11 13:47
 */
@Api(tags = "通知功能相关接口")
@RequestMapping("/image-serv")
@RestController
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @ApiOperation("根据对应条件分页查询通知")
    @ControllerLog(businessType = BusinessType.QUERY)
    @GetMapping("/notices")
    public HttpResult<Pagination<NoticeVO>> query(NoticeQuery noticeQuery) {
        Pagination<NoticeVO> pagination = noticeService.query(noticeQuery);
        return HttpResult.okWithData(pagination);
    }

    @ApiOperation("根据通知ID删除对应通知")
    @ControllerLog(businessType = BusinessType.DELETE)
    @DeleteMapping("/notice/{id}")
    public HttpResult<?> deleteById(@PathVariable Long id) {
        noticeService.deleteById(id);
        return HttpResult.okWithMessage("删除通知成功");
    }

    @ApiOperation("更新通知状态")
    @ControllerLog(businessType = BusinessType.UPDATE)
    @PutMapping("/notice")
    public HttpResult<?> updateStatus(@RequestBody NoticeForUpdateStatusDTO noticeForUpdateStatusDTO) {
        noticeService.updateStatus(noticeForUpdateStatusDTO);
        return HttpResult.okWithMessage("更新状态成功");
    }
}
